package learn.core.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

public class ShiroInterceptor implements Interceptor
{

	@Override
	public void intercept(Invocation inv)
	{
		Subject subject=SecurityUtils.getSubject();
		Session session=subject.getSession();
		ShiroPrincipal shiroPrincipal=(ShiroPrincipal)session.getAttribute("ShiroPrincipal");
		if(shiroPrincipal!=null)
		{
			shiroPrincipal.setMethodName(inv.getMethodName());
			shiroPrincipal.setMethodUrl(inv.getActionKey());
			session.setAttribute("ShiroPrincipal", shiroPrincipal);
		}
		inv.invoke();
	}

}
